from settings.publicvar import Base
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from typing_extensions import Annotated

int_pk = Annotated[int,mapped_column(primary_key=True)]
nameset = Annotated[str,mapped_column(String(15),nullable=True)]

class PersonBaseInfo(Base):
    __tablename__='personbaseinfo'

    id:Mapped[int_pk]
    name:Mapped[nameset]
    IDcard:Mapped[str] = mapped_column(String(18),nullable=False,unique=True)
    iphone:Mapped[str] = mapped_column(String(11),nullable=False)

class PersonOther(Base):
    __tablename__ = 'personother'

    id: Mapped[int_pk]
    name_id: Mapped[int] = mapped_column(ForeignKey('personbaseinfo.id'))
    person_type:Mapped[str]
    mark:Mapped[str] = mapped_column(nullable=True)

    personinfo:Mapped[PersonBaseInfo] = relationship(lazy=False, backref='personothers')

class PersonType(Base):
    __tablename__ = 'persontype'

    id: Mapped[int_pk]
    persontype:Mapped[str]
    mark: Mapped[str] = mapped_column(nullable=True)

class SurePersonType(Base):
    __tablename__ = 'suerpersontype'

    id: Mapped[int_pk]
    name_id: Mapped[int] = mapped_column(ForeignKey('personbaseinfo.id'))
    type_id: Mapped[int] = mapped_column(ForeignKey('persontype.id'))
    mark: Mapped[str] = mapped_column(nullable=True)

    personinfo: Mapped[PersonBaseInfo] = relationship(lazy=False, backref='personinfos')
    persontype: Mapped[PersonType] = relationship(lazy=False, backref='persontypes')